package foc.physics.solver;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import core.Global;
import core.ProblemType;

public class Main extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Global.loadFormulas(this);
        Global.loadProblems(this);

        setContentView(R.layout.main_menu);
        ListView list = (ListView) findViewById(R.id.main_menu_list);
        list.setAdapter(ArrayAdapter.createFromResource(this, R.array.main_menu_names,
                android.R.layout.simple_selectable_list_item));
        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i == 0) {
                    start("constant_acceleration");
                }
            }
        });
    }

    private void start(String problem) {
        Intent intent = new Intent(Main.this, GenericSolver.class);
        addExtras(Global.problems.get(problem), problem, intent);
        startActivity(intent);

    }


    public void addExtras(ProblemType type, String key, Intent intent) {

        intent.putExtra("size", type.units.length);
        intent.putExtra("units", type.units);
        intent.putExtra("variables", type.variables);
        intent.putExtra("key", key);
        intent.putExtra("formattedNames", type.variableNames);
    }
}